<?php require admin_tpl('header')?>

<div class="tab">
	<ul>
		<li><a href="admin.php?mod=link&ac=add" <?php if ($ac=='add'||$ac=='edit') {echo'class="on"';} ?>>添加链接</a></li>
		<li><a href="admin.php?mod=link" <?php if ($ac=='list') {echo'class="on"';} ?>>所有链接</a></li>
		<li><a href="admin.php?mod=link&ac=cate" <?php if ($ac=='cate') {echo'class="on"';} ?>>链接分类</a></li>
	</ul>
</div>
<div class="main">

<?php if ( $ac == 'list' ) { ?>
		<div class="search">
			<form name="search" method="get" action="admin.php">
			<input type="hidden" name="mod" value="link" />
				<fieldset>
					<legend>链接查找</legend>
						关键字：
						<input type="text" name="keyword" size="15" value="<?php echo $keyword?>" />
						<input type="submit" name="s" class="button" value="开始查找" />
						<input type="button" class="button" value="显示所有" onclick="window.location.href='admin.php?mod=link&ac=list'" />
						<input type="button" class="button" value="添加连接" onclick="window.location.href='admin.php?mod=link&ac=add'" />
				</fieldset>
			</form>
		</div>
		<form name="update" method="post" action="?mod=link">
			<table class="datalist" cellspacing="0" id="list">
				<tr>
					<th width="50" class="firstcol">选择</th>
					<th width="150">名称</th>
					<th>链接</th>
					<th width="100">分类</th>
					<th width="80">状态</th>
					<th width="80">排序</th>
					<th width="80">操作</th>
				</tr>
				<?php 
				if ( $result ) {
					foreach ($result as $row) {
				?>
				<tr id="row_<?php echo $row['id']?>">
					<td align="center"><input type="checkbox" name="id[]" value="<?php echo $row['id']?>" class="checkbox" /></td>
					<td><a href="?mod=link&ac=edit&id=<?php echo $row['id']?>"><?php echo $row['name']?></a></td>
					<td><a href="<?php echo $row['url']?>" target="_blank"><?php echo $row['url']?></a></td>
					<td align="center"><a href="?mod=link&cateid=<?php echo $row['cateid']?>"><?php echo $row['catename']?></a></td>
					<td align="center"><?php echo $row['status'] ? '<a href="?mod=link&ac=upstat&id='.$row['id'].'&val=0" class="suc">通过</a>' : '<a href="?mod=link&ac=upstat&id='.$row['id'].'&val=1" class="err">未审核</a>'?></td>
					<td align="center"><input type="text" name="order[<?php echo $row['id']?>]" value="<?php echo $row['orderid']?>" size="5" class="input" /></td>
					<td align="center"><a href="?mod=link&ac=edit&id=<?php echo $row['id']?>">编辑</a></td>
				</tr>
				<?php
					}
				} else {
					echo '<tr><td colspan="10">暂无记录...</td></tr>';
				}
				?>
				<tr>
					<td align="center"><input type="checkbox" class="checkbox" value="1" name="chkall" onclick="check_all(this)" /></td>
					<td colspan="8">全选 
					<input type="radio" name="ac" value="resort" id="resort" class="radio" checked="checked" onclick="$('#span_move').hide()" /><label for="resort">排序</label> 
					<input type="radio" name="ac" value="del" id="del" class="radio" onclick="$('#span_move').hide()" /><label for="del">删除</label> 
					<input type="radio" name="ac" value="move" id="move" class="radio" onclick="$('#span_move').show()" /><label for="move">移动到</label>
					<span id="span_move" style="display:none">
					<select name="cateid">
						<option value="">请选择</option>
						<?php echo cate_options('link')?>
					</select>
					</span>
					<input type="submit" class="submit" value="执行操作"/>
				</tr>
				<tr>
					<td colspan="10"><?php echo multipage()?></td>
				</tr>
			</table>
		</form>
<?php } elseif ( $ac == 'add' || $ac == 'edit' ) { ?>
	<form name="save" method="post" action="?mod=link&ac=save" onsubmit="return save_link()">
	<input type="hidden" name="id" value="<?php echo $result['id']?>" />
	<table width="100%" cellspacing="0" class="sub">
		<tr>
			<td colspan="2"><div id="tip"></div></td>
		</tr>
		<tr>
			<td width="80" align="right">名称：</td>
			<td><input type="text" name="name" class="input" size="20" value="<?php echo $result['name']?>" /> 
			<select name="cateid"><?php echo cate_options('link',$result['cateid'])?></select>
			</td>
		</tr>
		<tr>
			<td align="right">URL：</td>
			<td><input type="text" name="url" class="input" size="50" value="<?php echo $result['url']?>" /> <span>别忘了加上http://</span></td>
		</tr>
		<tr>
			<td align="right">LOGO：</td>
			<td><input type="text" name="logo" class="input" size="50" value="<?php echo $result['logo']?>" /> <span>别忘了加上http://</span></td>
		</tr>
		<tr>
			<td align="right">描述：</td>
			<td><textarea name="description" rows="5" cols="50"><?php echo $result['description']?></textarea>
			</td>
		</tr>
		<tr>
			<td align="right">其它：</td>
			<td>
			<input type="radio" name="status" id="status_1" value="1" class="checkbox" <?php if ($result['status']) {echo'checked';} ?> /><label for="status_1">通过</label>
			<input type="radio" name="status" id="status_0" value="0" class="checkbox" <?php if (!$result['status']) {echo'checked';} ?> /><label for="status_0">未审核</label> 
			</td>
		</tr>
		<tr class="bg2"><td></td><td><input type="submit" class="button" value="保存链接" /> <input type="button" class="button" onclick="history.back();" value="取消返回" /></td></tr>
	</table>
	</form>
<?php } elseif ( $ac == 'cate' ) { ?>
	<form name="update" method="post" action="?mod=link&ac=savecate">
		<table class="datalist" cellspacing="0" id="link_list">
			<tr>
				<th width="50" class="firstcol">ID</th>
				<th width="200">组名</th>
				<th width="100">排序</th>
				<th width="100">链接数量</th>
				<th width="100">操作</th>
				<th>&nbsp;</th>
			</tr>
			<?php foreach ($result as $row) { ?>
			<tr id="linkgroup_<?php echo $row['id']?>">
				<td align="center"><?php echo $row['id']?></td>
				<td><input type="text" name="catename[<?php echo $row['id']?>]" value="<?php echo $row['catename']?>" /></td>
				<td align="center"><input type="text" name="orderid[<?php echo $row['id']?>]" value="<?php echo $row['orderid']?>" size="5" /></td>
				<td align="center"><a href="?mod=link&cid=<?php echo $row['id']?>"><b style="color:green"><?php echo $row['count']?></b></a></td>
				<td align="center"><a href="?mod=link&ac=delcate&id=<?php echo $row['id']?>" >删除</a></td>
				<td>&nbsp;</td>
			</tr>
			<?php }?>
			<tr>
				<td align="center">新增</td>
				<td><input type="text" name="newname" value="" /></td>
				<td align="center"><input type="text" name="neworderid" value="0" size="5" /></td>
				<td colspan="5">&nbsp;</td>
			</tr>
			<tr>
				<td colspan="10"><input type="submit" class="button" name="s" value="更新分类" /></td>
			</tr>
		</table>
	</form>
<?php } ?>

</div>

<?php require admin_tpl('footer')?>